package org.zdc.pivot.wtk;
import flash.geom.Point;
import haxe.Json;
import org.zdc.pivot.core.ISerializable;
import org.zdc.pivot.error.IllegalArgumentException;

class Point extends nme.geom.Point, implements ISerializable
{
	private static inline var serialVersionUID = 5193175754909343769;
	
    public static inline var X_KEY:String = "x";
    public static inline var Y_KEY:String = "y";
	
	public function new(x:Int = 0, y:Int = 0) 
	{
		super(x, y);
	}
	
    public function hashCode():Int {
        return Std.int(31 * x  + y);
    }
	
	public function translate(dx:Int, dy:Int):Point {
		return new Point(Std.int(x + dx), Std.int(y + dy));
	}
	
	public function decode(value:String):Point {
		if (value == "") {
			throw new IllegalArgumentException();
		}
		try {
			var json = Json.parse(value);
			return new Point(json.x, json.y);
		}
		catch (e:Dynamic) {
			return null;
		}
	}
}